package com.ruoyi.websocket.handler.impl;

import com.ruoyi.websocket.handler.IMessageProcessor;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 * 测试用，实际要自己定义
 */
@Component
@ConditionalOnProperty(prefix = "netty-config", name = "enabled-test", havingValue = "true")
@Slf4j
public class MessageProcessorTest implements IMessageProcessor {
    @Override
    public void handlerAdded(ChannelHandlerContext ctx) {
        log.info("新的连接加入");
    }

    @Override
    public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame) {
        String request = frame.text();
        log.info("receive_message1:{}",request);
    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) {
        log.info("连接已关闭");
    }
}
